from django.db import models

# Create your models here.
class Users(models.Model):
    username=models.CharField(max_length=20)
    password=models.CharField(max_length=77)
    phone=models.CharField(max_length=11)
    email=models.CharField(max_length=100,null=True)
    age=models.IntegerField(null=True)
    sex=models.CharField(max_length=1,choices=(('1','男'),('0','女')),null=True)
    pic_url=models.CharField(max_length=255) 
    status=models.IntegerField(default=0)  #状态
    addtime=models.DateTimeField(auto_now_add=True)



class Cates(models.Model):
    name=models.CharField(max_length=30)
    pid=models.IntegerField()
    path=models.CharField(max_length=30)
    isDelete=models.BooleanField(default=True)

    def __str__(self):
        return self.path

class Goods(models.Model):
  # 标题
  title = models.CharField(max_length=70)
  # 外建
  cateid = models.ForeignKey(to='Cates')
  # 商品图像
  pic_url=models.CharField(max_length=200)
  # 库存量
  gnum = models.IntegerField()
  # 单价
  price=models.FloatField()
  # 描述
  info = models.TextField(max_length=255)
  # 状态
  status = models.IntegerField(default=0)
  # 访问量
  clicknum = models.IntegerField(default=0)
  # 销售量
  ordenum = models.IntegerField(default=0)
  # 上架时间
  addtime=models.DateTimeField(auto_now_add=True)


class Cart(models.Model):
  uid = models.ForeignKey(to='Users')
  gid = models.ForeignKey(to='Goods')
  gnum = models.IntegerField()

# 地址 
class Address(models.Model):
  # uid 省 市 县/区 收货人 联系方式 详细地址
  uid = models.ForeignKey(to="Users")
  shr = models.CharField(max_length=10)
  phone = models.CharField(max_length=11)
  # 外键
  zhen = models.ForeignKey(to='Citys')

  info = models.CharField(max_length=255)

  isselect = models.BooleanField(default=0)




# 城市
class Citys(models.Model):
  name=models.CharField(max_length=30)
  level = models.IntegerField()
  upid = models.IntegerField()


class Order(models.Model):
  # id uid 地址 物流信息  支付信息 状态
  # 1   1   
  uid=models.ForeignKey(to='Users')
  addr=models.CharField(max_length=255)
  wl=models.CharField(max_length=50)
  paytype=models.CharField(max_length=30)
  price=models.IntegerField(default=0)
  # 0 未付款 1已付款 2未发货 3已发货
  status=models.IntegerField(default=0)
  addtime=models.DateTimeField(auto_now_add=True)


# 订单详情
# orderid  gid  商品标题  购买数量
class Orderinfo(models.Model):
  ordid = models.ForeignKey(to='Order')
  gid   = models.IntegerField()
  title = models.CharField(max_length=101)
  num   = models.IntegerField()
  pic_url=models.CharField(max_length=100)